package vn.edu.saigontech.ncms.model.user;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.OptimisticLockType;

import vn.edu.saigontech.ncms.model.BaseEntity;
import vn.edu.saigontech.ncms.util.DateUtil;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, optimisticLock = OptimisticLockType.ALL)
@Table(name = "ncms_logging")
@SuppressWarnings("serial")
public class LoggingRecord extends BaseEntity {
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id", nullable = false)
	private User actor;

	@Column(name = "description")
	private String description;

	@Column(name = "interacted_action")
	private String interactedAction;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "interacted_date")
	private Date interactedDate;

	public String getDate() {
		String ret = DateUtil.toString(this.interactedDate, "MM/dd/yyyy hh:mm:ss");
		return ret;
	}
	
	public User getActor() {
		return actor;
	}

	public void setActor(User actor) {
		this.actor = actor;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getInteractedAction() {
		return interactedAction;
	}

	public void setInteractedAction(String interactedAction) {
		this.interactedAction = interactedAction;
	}

	public Date getInteractedDate() {
		return interactedDate;
	}

	public void setInteractedDate(Date interactedDate) {
		this.interactedDate = interactedDate;
	}
	
	@Override
	public String toString() {
		return "User: " + this.actor.getUsername() + "; Description: "
				+ this.description +"; Time: " + DateUtil.toString(this.getInteractedDate(), "MM/dd/yyyy hh:mm:ss");
	}
}